<?php

namespace app\admin\model\order;

use think\Model;


class Order extends Model
{
    // 表名
    protected $name = 'learn_course_order';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;
    // 追加属性
    protected $append = [
        'type_text'

    ];

    public function getTypeList()
    {
        return ['0' => __('Type 0'), '1' => __('Type 1'), '2' => __('Type 2')];
    }

    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function course()
    {
        $model = new \app\admin\model\learn\Course;
        return $model->belongsTo('Course', 'learn_course_id', 'id', [], 'left')->setEagerlyType(0);
    }

    public function user()
    {
        $model = new \addons\third\model\Third;
        return $model->belongsTo('Third', 'user_id', 'id', [], 'left')->setEagerlyType(0);
    }
    public function orgcate()
    {
        $model = new \app\admin\model\OrgCate;
        return $model->belongsTo('OrgCate', 'org_cate_id', 'id', [], 'left')->setEagerlyType(0);
    }

}
